package com.ys.servers.common.util;

import com.ys.servers.common.data.ReturnData;
import io.vertx.core.AsyncResult;
import io.vertx.core.Future;
import io.vertx.core.impl.CompositeFutureImpl;

import java.util.List;
import java.util.stream.Collectors;
import io.vertx.core.json.JsonObject;
/**
 * Created by taotao on 2017/3/7.
 */
public class CommonUtils {

    public static <R> Future<List<R>> sequenceFuture(List<Future<R>> futures) {
        return CompositeFutureImpl.all(futures.toArray(new Future[futures.size()]))
                .map(v -> futures.stream()
                        .map(Future::result)
                        .collect(Collectors.toList())
                );
    }

    public static boolean validAsyncResult(AsyncResult r) {
        if (r == null)
            return false;
        return r.succeeded() && r.result() != null;

    }

    public static boolean sucAsyncResult(AsyncResult r) {
        if (r == null)
            return false;
        return r.succeeded();

    }

    public static void main(String[] args){
        String versions="1.4.235.2234";

        versions.replace(".",";");
        String tryVersionBig="";
        String[] vDigits = versions.split("\\.");
        if (vDigits.length > 3) {
             tryVersionBig = vDigits[0] + "." + vDigits[1] + "." + vDigits[2];
        }
        System.out.println(tryVersionBig);
    }

    public static ReturnData validateJsonFiled(JsonObject paras, String ... fields){
        ReturnData result=new ReturnData();
        result.setError(false);
        JsonObject errorParas= new JsonObject();
      /*  Arrays.stream(fields).forEach(field->{
            String content= paras.getString(field);
            if(null==content||content.equals("")){
                result.setError(true);
                errorParas.("error","Param : "+field +" could not be null or empty .");
            }
        });*/

        return result;
    }
}
